﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DataCentral.UsecaseControllers;
using DataCentral.Dataset;

namespace DataCentral.UserControls
{
    public partial class TablesConfigControl : DataCentral.CommonCenterControl
    {
        SynchronizeUsecase _UCSynchronize;
        public TablesConfigControl()
        {
            InitializeComponent();
            _UCSynchronize = new SynchronizeUsecase();
        }


        private void TablesConfigControl_Load(object sender, EventArgs e)
        {
            ValueListClass clValueList = new ValueListClass();
            iluCSDL.DataSource = clValueList.GetDatabaseConfigList();
            daTablesConfig.Fill(dsCentral.TablesConfiguration);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            _UCSynchronize.StartUsecase(dsCentral,false, null);
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (viewTables.GetDataRow(viewTables.FocusedRowHandle) != null)
            {
                _UCSynchronize.StartUsecase(dsCentral,true, (DataCentralDataset.TablesConfigurationRow)viewTables.GetDataRow(viewTables.FocusedRowHandle));
            }
        }

        private void viewTables_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            btnEdit.Enabled = viewTables.GetDataRow(viewTables.FocusedRowHandle) != null;
        }

        private void viewTables_DoubleClick(object sender, EventArgs e)
        {
            btnEdit_Click(null, null);
        }
    }
}
